<? defined('SYSPATH') or die('No direct script access');

class Events_Controller extends Template_Controller {

    public $template = 'kohana/template';

    public function index()
    {

        $events = ORM::factory('event')->find_all();

        $view = new View('event_content');
        $view->events = $events;

        $this->template->title = 'Events';
        $this->template->content = $view;
    }

    public function add()
    {

        $event = ORM::factory('event');

        if($_POST)
        {
            $event->name = $_POST['name'];
            $event->description = $_POST['description'];


            $event->save();

            url::redirect('events');
        }
        else
        {
            $view = new View('new_event');

            $this->template->title = 'New Event';
            $this->template->content = $view;
        }
    }

    public function delete($id)
    {
        ORM::factory('event', $id)->delete();

        url::redirect('events');
    }

    public function view($id)
    {
        $event = ORM::factory('event', $id);

        $view = new View('view_event');
        $view->event = $event;

        $this->template->title = $event->name;
        $this->template->content = $view;
    }
}

?>
